import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
// import path from 'path'
import {viteSingleFile} from "vite-plugin-singlefile"
import VueDevTools from 'vite-plugin-vue-devtools'
import {resolve} from 'path'

import env from "./src/request/env.js";

// https://vitejs.dev/config/
export default defineConfig({
    base: "./",
    plugins: [
        VueDevTools(),
        vue(),
        viteSingleFile()
    ],
    resolve: {
        alias: [
            {
                find: '@', //指向的是src目录
                replacement: resolve(__dirname, 'src')
            }
        ]
    },
    server: { //主要是加上这段代码
        host: '127.0.0.1',
        port: 3000,
        proxy: {
            '/kapi': {
                target: env[env.activeProfile].host,	//实际请求地址
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/kapi/, env[env.activeProfile].rewritePrefix ? '/kapi' : '')
            },
        }
    }
})
